// Author : Mariam Nahapetyan // Lab : Dilijan Fab Lab // Version .02 #include // Libraries to run motors #include const int Up_Switch = 8; //PB0 pin const int Down_Switch = 9; //PB1 pin int Set_Point_up =650 ; //Initilized Set Point_up value for photoresistor int Set_Point_down =400 ; //Initilized Set Point_down value for photoresistor const int pResistor = A0; //PC0 pin AF_DCMotor motor(3); //Initilized DC motor for pin PB3 void setup() { Serial.begin(9600); pinMode(Up_Switch, INPUT); // Up_Switch as input pinMode(Down_Switch, INPUT); // Down_Switch as input pinMode(pResistor, INPUT); // Photoresistor pin as an input to read ADC Serial.println("Starting"); // It prints text on serial monitor motor.setSpeed(50); // Set speed of motor motor.run(RELEASE); // Motor starting condition is stop } void loop() { if(analogRead(pResistor)<= 400){ // It's very bright and curtain should go up while Up_Switch is not pressed.. motor.run(FORWARD); // Motor is runing FORWARD(up) while(Up_Switch != HIGH){ // Runing while loop until Up_Switch is not pressed Serial.println(analogRead(pResistor)); // It prints ADC value from photoresistor(from 0 to 1023) on serial monitor } motor.run(RELEASE); // After switch is pressed this command will stop motor delay(1000); // delay 1 second } else if(analogRead(pResistor) >=600){ // It's very dark and curtain should go up while Up_Switch is not pressed... motor.run(BACKWARD); // Motor is runing BACKWARD(down) while(Down_Switch != HIGH){ // Runing while loop until Down_Switch is not pressed Serial.println(analogRead(pResistor)); // It prints ADC value from photoresistor(from 0 to 1023) on serial monitor } motor.run(RELEASE); // After switch is pressed this command will stop motor delay(1000); // delay 1 second } }